package com.turing.usdtpay.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.turing.usdtpay.R;
import com.turing.usdtpay.entity.StreamData;
import com.turing.usdtpay.utils.FormatUtils;

import java.util.List;

/**
 * @作者：JAY
 * @创建时间：2019/10/16 14:25
 * @描述：
 **/
public class PropertyAdapter extends RecyclerView.Adapter<PropertyAdapter.Holder> {

    private Context mContext;
    private List<StreamData> mStreamDataList;
    private Holder holder;

    public PropertyAdapter(Context context, List<StreamData> streamDataList) {
        this.mContext = context;
        this.mStreamDataList = streamDataList;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_property, parent, false);
        holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(PropertyAdapter.Holder holder, int position) {
        StreamData data = mStreamDataList.get(position);
        holder.mName.setText(data.getName());
        holder.mTime.setText(data.getTime());
        holder.mCNY.setText(FormatUtils.NoumberFromat2(data.getCny()));
        holder.mRest.setText(FormatUtils.NoumberFromat2(data.getRest()));
        holder.mCount.setText(FormatUtils.NoumberFromat8(data.getUsdt()));
    }

    public void updataData(List<StreamData> list){
        mStreamDataList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mStreamDataList.size();
    }

    public class Holder extends RecyclerView.ViewHolder{
        private TextView mTime,mCNY,mRest,mCount,mName;
        public Holder(View itemView) {
            super(itemView);
            mName = (TextView) itemView.findViewById(R.id.item_name);
            mTime = (TextView) itemView.findViewById(R.id.item_time);
            mCNY = (TextView) itemView.findViewById(R.id.item_cny);
            mRest = (TextView) itemView.findViewById(R.id.item_rest);
            mCount = (TextView) itemView.findViewById(R.id.item_count);
        }
    }
}
